package com.myproject.jdbc;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.SQLException;

public class Druid {

    public static void main(String[] args) {

        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/giftcptdb?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false");
        //dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/giftmalldb?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false");
        //dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/giftmgmdb?characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false");
        dataSource.setUsername("root");
        dataSource.setPassword("root123");

        //连接池配置
        dataSource.setMaxActive(200);
        dataSource.setMinIdle(10);
        dataSource.setInitialSize(10);
        dataSource.setMaxWait(60000);
        dataSource.setTimeBetweenEvictionRunsMillis(60000);
        dataSource.setMinEvictableIdleTimeMillis(30000);
        dataSource.setTestWhileIdle(true);
        dataSource.setTestOnBorrow(false);
        dataSource.setTestOnReturn(false);
        dataSource.setValidationQuery("SELECT 1");

        dataSource.setPoolPreparedStatements(true);
        dataSource.setMaxPoolPreparedStatementPerConnectionSize(20);

        try {
            dataSource.init();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
